using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
	[DataObject(true)]
    public partial class SubcategoryController
    {
	
		public SqlDataProvider DataProvider { get; set; }

        public SubcategoryController()
        {
            DataProvider = new SqlDataProvider();
        }
	
		[DataObjectMethod(DataObjectMethodType.Insert, true)]
        public Guid InsertSubcategory(SubcategoryInfo oi)
		{
            return DataProvider.InsertSubcategory(oi.CategoryId, oi.Name);
		}

		[DataObjectMethod(DataObjectMethodType.Update, true)]
        public int UpdateSubcategory(SubcategoryInfo oi) 
		{
			return DataProvider.UpdateSubcategory(oi.SubcategoryId, oi.CategoryId, oi.Name);
		}
		
		[DataObjectMethod(DataObjectMethodType.Delete, true)]
        public int DeleteSubcategory(Guid subcategoryId)
		{
			return DataProvider.DeleteSubcategory(subcategoryId);
        }

		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public SubcategoryInfo SelectSubcategory(Guid subcategoryId)
        {    
			return ObjectFromDataRow(DataProvider.SelectSubcategory(subcategoryId));
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<SubcategoryInfo> SelectSubcategories()
		{
            return ListFromDataTable(DataProvider.SelectSubcategories());
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<SubcategoryInfo> SelectSubcategories(string sortExpression)
        {
            List<SubcategoryInfo> retList = SelectSubcategories();
            if (sortExpression.Length > 0)
            {
                retList.Sort(new SubcategoryComparer(sortExpression));
            }
            return retList;
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<SubcategoryInfo> SelectSubcategoriesByCategory(Guid categoryId)
		{
			return ListFromDataTable(DataProvider.SelectSubcategoriesByCategory(categoryId));
		}
		
        public List<SubcategoryInfo> SelectSubcategoriesByCategory(Guid categoryId,string sortExpression)
		{
			List<SubcategoryInfo> retList = SelectSubcategoriesByCategory(categoryId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new SubcategoryComparer(sortExpression));
            }
            return retList;
		}

	}

}
		